//
//  CustomViewController.m
//  1gene
//
//  Created by 1jiyin on 16/2/26.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "CustomViewController.h"
#import "HomePageViewController.h"
#import "ProductViewController.h"

@interface CustomViewController ()<UITabBarControllerDelegate>

@end

@implementation CustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate=self;
    self.view.backgroundColor=[UIColor whiteColor];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 49)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:backView atIndex:0];
    self.tabBar.opaque = YES;
    [self createTabeBar];
    // Do any additional setup after loading the view.
}
-(void)createTabeBar
{
    //首页
    UINavigationController *home=[[UINavigationController alloc]initWithRootViewController:[[HomePageViewController alloc]init]];
    UIImage *normalImg1=[UIImage imageNamed:@"home_normal"];
    normalImg1=[normalImg1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImg1=[UIImage imageNamed:@"home_selected"];
    selectedImg1=[selectedImg1 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    home.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"首页" image:normalImg1 selectedImage:selectedImg1];
    
    //产品
    UINavigationController *product=[[UINavigationController alloc]initWithRootViewController:[[ProductViewController alloc]init]];
    UIImage *normalImg2=[UIImage imageNamed:@"product_normal"];
    normalImg2=[normalImg2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImg2=[UIImage imageNamed:@"product_selected"];
    selectedImg2=[selectedImg2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    product.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"产品" image:normalImg2 selectedImage:selectedImg2];
    
    //社区
    UINavigationController *community=[[UINavigationController alloc]initWithRootViewController:[[CommunityViewController alloc]init]];
    UIImage *normalImg3=[UIImage imageNamed:@"community_normal.png"];
    normalImg3=[normalImg3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImg3=[UIImage imageNamed:@"community_selected.png"];
    selectedImg3=[selectedImg3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    community.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"社区" image:normalImg3 selectedImage:selectedImg3];
    
    //我的
    UINavigationController *my=[[UINavigationController alloc]initWithRootViewController:[[MyViewController alloc]init]];
    UIImage *normalImg4=[UIImage imageNamed:@"my_normal.png"];
    normalImg4=[normalImg4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImg4=[UIImage imageNamed:@"my_selected.png"];
    selectedImg4=[selectedImg4 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    my.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"我的" image:normalImg4 selectedImage:selectedImg4];
    
    self.viewControllers=@[home,product,community,my];
    //self.tabBar.selectedImageTintColor=[UIColor colorWithRed:217/255.0 green:124/255.0 blue:32/255.0 alpha:1];
    self.tabBar.tintColor=[UIColor colorWithRed:87/255.0 green:187/255.0 blue:215/255.0 alpha:1];
//    [self.tabBarItem setTitleTextAttributes:[NSDictionary
//                                             dictionaryWithObjectsAndKeys: [UIColor colorWithRed:87/255.0 green:187/255.0 blue:215/255.0 alpha:1],
//                                              UITextAttributeTextColor, nil]  forState:UIControlStateNormal];
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    UINavigationController *nv=(id)viewController;
    AppDelegate *app=[[UIApplication sharedApplication]delegate];
    if ([nv.tabBarItem.title isEqualToString:@"首页"]) {
        app.tabbarItemTag=0;
    }else if ([nv.tabBarItem.title isEqualToString:@"产品"])
    {
        app.tabbarItemTag=1;
    }else if ([nv.tabBarItem.title isEqualToString:@"社区"])
    {
        app.tabbarItemTag=2;
    }
    NSLog(@".......................%@",nv.tabBarItem.title);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end




















































